//
//  CYTabCell.m
//  TheAddressBookDemo
//
//  Created by 郭颢源 on 2020/10/16.
//  Copyright © 2020 YangLei. All rights reserved.
//


#import "CYTabCell.h"

@interface CYTabCell ()
//气泡弹窗
@property (nonatomic, strong)UILabel *label;
//文本
@property (nonatomic, strong)UIImageView *imgView;

@end

@implementation CYTabCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //只是为了代码清晰，和懒加载没啥关系
        [self.contentView addSubview:self.imgView];
        [self.contentView addSubview:self.label];
    }
    return self;
}

- (UILabel *)label {
    if (!_label) {
        _label = [[UILabel alloc] init];
        _label.font = [UIFont systemFontOfSize:15];
        _label.textColor = [UIColor blackColor];
        //设置最大宽度
        _label.preferredMaxLayoutWidth = 300;
        _label.numberOfLines = 0;
    }
    return _label;
}

- (UIImageView *)imgView {
    if (!_imgView) {
        _imgView = [[UIImageView alloc] init];
        _imgView.backgroundColor = [UIColor orangeColor];
        _imgView.layer.cornerRadius = 5;
        _imgView.layer.masksToBounds = YES;
        [self.contentView addSubview:_imgView];
    }
    return _imgView;
}

- (void)setStr:(NSString *)str {
    _str = str;
    _label.text = _str;

    [_label mas_updateConstraints:^(MASConstraintMaker *make) {
        //不要设置 left
        make.top.equalTo(_label.superview.mas_top).offset(15);
        make.right.equalTo(_label.superview.mas_right).offset(-40);
        make.bottom.equalTo(_label.superview.mas_bottom).offset(-15);
    }];

    [_imgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_label).offset(-15);
        make.top.equalTo(_label).offset(-10);
        make.bottom.mas_equalTo(_label).offset(10);
        make.right.mas_equalTo(_label).offset(15);
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
